//
//  SN_AboutSN_Controller.m
//  Shiyun_Newspaper
//
//  Created by zz on 17/6/28.
//  Copyright © 2017年 ShiYun. All rights reserved.
//

#import "SN_AboutSN_Controller.h"
#import "SN_WebViewController.h"

@interface SN_AboutSN_Controller () <UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIView *headerView;
@property (nonatomic, strong) UIWebView *phoneCallWebView;
@end

@implementation SN_AboutSN_Controller

#pragma mark -Getter
- (UITableView *)tableView {
    
    if (!_tableView) {
        
        
        
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, SafeAreaTopHeight, VIEW_WIDTH, VIEW_HEIGHT - SafeAreaTopHeight) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.scrollEnabled = false;
        UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, VIEW_WIDTH, VIEW_HEIGHT)];
        
        _tableView.tableHeaderView = self.headerView;
        
        footerView.backgroundColor = [UIColor colorWithHexString:@"#f4f5f7"];
        _tableView.tableFooterView = footerView;
        _tableView.rowHeight = 44;
        
    }
    
    return _tableView;
}

- (UIView *)headerView {
    
    if (!_headerView) {
        
        _headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, VIEW_WIDTH, 175)];
        _headerView.backgroundColor = [UIColor colorWithHexString:@"#f4f5f7"];
        UIImageView *logoImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 15, 85, 85)];
        [logoImgView setImage:[UIImage imageNamed:@"APPicon170"]];
        logoImgView.centerX = _headerView.centerX;
        [_headerView addSubview:logoImgView];
        
        //版本
        UILabel *versionLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(logoImgView.frame) + 25, VIEW_WIDTH, 17)];
        versionLabel.textColor = [UIColor colorWithHexString:@"#3b3b3b"];
        versionLabel.font = [UIFont systemFontOfSize:17];
        versionLabel.textAlignment = NSTextAlignmentCenter;
        versionLabel.text = @"师云-少智版 V1.2";
        [_headerView addSubview:versionLabel];
    }
    
    return _headerView;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navBar.navigationItem.title = @"关于师云-少智版";
    [self.view addSubview:self.tableView];
    
    UIButton *phoneBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [phoneBtn setTitleColor:[UIColor colorWithHexString:@"#fb524a"] forState:UIControlStateNormal];
    [phoneBtn setTitle:@"客服热线 400-667-8009" forState:UIControlStateNormal];
    phoneBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [phoneBtn setFrame:CGRectMake((VIEW_WIDTH - 200) / 2, VIEW_HEIGHT - 50 - 30, 200, 50)];
    [phoneBtn addTarget:self action:@selector(phoneAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:phoneBtn];
}

#pragma mark -UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [[UITableViewCell alloc] init];
    cell.textLabel.frame = CGRectMake(15, 15, 14, 200);
    cell.textLabel.font = [UIFont systemFontOfSize:14];
    cell.textLabel.textColor = [UIColor colorWithHexString:@"#3b3b3b"];
    
    switch (indexPath.section) {
        case 0:
            cell.textLabel.text = @"服务协议";
            break;
        case 1:
            cell.textLabel.text = @"隐私政策";
            break;
            
        default:
            break;
    }
    
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

#pragma mark -UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    
    return 5;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    
    UIView *view = [[UIView alloc] init];
    
    view.backgroundColor = [UIColor colorWithHexString:@"#f4f5f7"];
    return view;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    SN_WebViewController *webVC = [[SN_WebViewController alloc]init];
    
    if (indexPath.section == 0) {
        
        webVC.url = @"http://szb.our100.net/about/rlsysm/fwxy.html";
        
    }else if (indexPath.section == 1) {
        webVC.url = @"http://szb.our100.net/about/rlsysm/yszc.html";
    }
    
    [self.navigationController pushViewController:webVC animated:YES];
    
}

#pragma mark -phoneAction 
- (void)phoneAction {

    NSString *phoneNum=@"400-667-8009";
    NSURL *phoneURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",phoneNum]];
    
    if ( !_phoneCallWebView ) {
        _phoneCallWebView = [[UIWebView alloc]initWithFrame:CGRectZero];// 这个webView只是一个后台的容易 不需要add到页面上来 效果跟方法二一样 但是这个方法是合法的
    }
    
    [_phoneCallWebView loadRequest:[NSURLRequest requestWithURL:phoneURL]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
